/*
 * Copyright (c) 2023 IUV Inc. All rights reserved.
 * 项目名称：IUV TXY
 * 文件名：HaoMaBaiKeUtil.java
 * Date：23-10-10 下午2:09
 * Author：Will
 */

package com.iuv.baike.util;

import com.aliyun.dytnsapi20200217.Client;
import com.aliyun.dytnsapi20200217.models.PhoneNumberStatusForPublicRequest;
import com.aliyun.dytnsapi20200217.models.PhoneNumberStatusForPublicResponse;
import com.aliyun.teaopenapi.models.Config;

/**
 * 号码百科工具类
 *
 * @author Will
 * @date 17:04
 */
public class HaoMaBaiKeUtil {
    /**
     * 产品域名,开发者无需替换
     */
    static final String domain = "dytnsapi.aliyuncs.com";

    /**
     * 用户AccessKey
     */
    static final String accessKeyId = "LTAI4GEUrnLSZgRPjCcfFSik";
    /**
     * AccessKey密钥
     */
    static final String accessKeySecret = "jr97i2IMItJUpbzjEu2PoEMXFkhXoY";

    static final String authCode = "cV2KfC80E6";

    /**
     * 查询号码状态发送
     *
     * @param phoneNumber   手机号码
     * @return
     */
    public static PhoneNumberStatusForPublicResponse queryOnlineTime(String phoneNumber) {

        PhoneNumberStatusForPublicResponse phoneNumberStatusForPublicResponse = null;

        PhoneNumberStatusForPublicRequest phoneNumberStatusForPublicRequest=new PhoneNumberStatusForPublicRequest();
        phoneNumberStatusForPublicRequest.setInputNumber(phoneNumber);
        phoneNumberStatusForPublicRequest.setAuthCode(authCode);
        phoneNumberStatusForPublicRequest.setMask("NORMAL");

        try {
            //初始化acsClient,暂不支持region化
            Client client= createClient(accessKeyId,accessKeySecret);
            //发送请求
            phoneNumberStatusForPublicResponse = client.phoneNumberStatusForPublic(phoneNumberStatusForPublicRequest);
            System.out.println(com.aliyun.teautil.Common.toJSONString(phoneNumberStatusForPublicResponse));
        } catch (Exception e) {
            e.printStackTrace();
        }
        return phoneNumberStatusForPublicResponse;
    }

    public static Client createClient(String accessKeyId, String accessKeySecret) throws Exception {
        Config config = new Config()
                // 必填，您的 AccessKey ID
                .setAccessKeyId(accessKeyId)
                // 必填，您的 AccessKey Secret
                .setAccessKeySecret(accessKeySecret);
        config.endpoint =domain;
        return new com.aliyun.dytnsapi20200217.Client(config);
    }

}
